"""shop URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.views.generic import TemplateView
from rest_framework.routers import DefaultRouter
from django.contrib import admin
from django.urls import path, re_path
from django.views.static import serve
from rest_framework.schemas import get_schema_view

from shop.settings import MEDIA_ROOT, STATIC_ROOT
from django.conf.urls import url, include
from goods.views import ProductListViewSet, GoodCategoryViewSet, GoodCategoryBrandViewSet, CategoryBrandViewSet, \
    HotProductListViewSet, GoodListViewSet, AttributeViewSet, SPGViewSet, ParamViewSet
from users.views import SMSViewSet, UserRegisterViewSet, UserAddressViewSet, WeiboLogin, trigger_error, \
    CustomJSONWebTokenAPIView, CustomObtainJSONWebToken, QueryUser
from managements.views import global_info, global_login, global_logout, update_cate, update_nav, update_status, \
    withChildren, \
    productAttribute, listAll, create, returnReason, role, member, test_upload_file
from trades.views import ShoppingCartViewSet, PayInfoViewSet, AliPayViewSet, SuperPayInfoViewSet, UpdatePayStatus, \
    BuyPayInfoViewSet
from managements.views import SuperGoodListViewSet, SuperGoodCategoryViewSet, SecondGoodCategoryViewSet, \
    ThirdGoodCategoryViewSet, role_list, ReturnGoodViewSet, SystemSetViewSet, GoodBrandViewSet, SuperUserListViewSet, \
    NoticeViewSet
from operation.views import UserFavViewSet, UserMessageViewSet
from managements.views import MenuListViewSet, RoleListViewSet, ReturnReasonViewSet, IndexCarouselGoodViewSet, RegionViewSet
from rest_framework_jwt.views import obtain_jwt_token
from rest_framework.documentation import include_docs_urls

routers = DefaultRouter()
# 前台接口
# 注意  一个产品有多个商品
# 价格 销量排序
routers.register(r'products', ProductListViewSet)  # 产品
# 新品 促销 有货
routers.register(r'goods', GoodListViewSet)  # 商品
routers.register(r'categories', GoodCategoryViewSet)  # 分类
routers.register(r'code', SMSViewSet, 'codes')  # 验证码
# 商品参数
routers.register(r'spg', SPGViewSet, 'spg')  # spg分类
routers.register(r'attribute', AttributeViewSet, 'attribute')  # 属性
routers.register(r'param', ParamViewSet, 'param')  # 参数
routers.register(r'users', UserRegisterViewSet, 'users')  # 注册登录
routers.register(r'collect', UserFavViewSet, 'fav')  # 搜藏
routers.register(r'messages', UserMessageViewSet, 'messages')  # 建议/反馈
routers.register(r'address', UserAddressViewSet, 'address')  # 地址
routers.register(r'carts', ShoppingCartViewSet, 'carts')  # 购物车
routers.register(r'orders', PayInfoViewSet, 'orders')  # 下单
routers.register(r'buy', BuyPayInfoViewSet, 'buy')  # 下单
routers.register(r'banners', GoodCategoryBrandViewSet, 'banners')  # 轮播
routers.register(r'recommends', CategoryBrandViewSet, 'recommends')
routers.register(r'notices', NoticeViewSet, 'notices')  # 公告/消息
routers.register(r'region', RegionViewSet, 'region')

# routers.register(r'hots', HotProductListViewSet, 'hots')  # 热卖

# updatePayStatus
# routers.register(r'updatePayStatus', UpdatePayStatus, 'updatePayStatus')


# 后端管理
routers.register(r'managements/goods', SuperGoodListViewSet, 'supergoods')
routers.register(r'managements/category', SuperGoodCategoryViewSet, 'supercate')
routers.register(r'second/cate', SecondGoodCategoryViewSet, 'secondcate')
routers.register(r'managements/order', SuperPayInfoViewSet, 'superorder')
routers.register(r'managements/user', SuperUserListViewSet, 'superuser')
routers.register(r'managements/menus', MenuListViewSet, 'menus')
routers.register(r'managements/register', SuperUserListViewSet, 'admin_register')
routers.register(r'productAttribute', ThirdGoodCategoryViewSet, 'productAttribute')
routers.register(r'managements/setting', SystemSetViewSet, 'setting')
routers.register(r'managements/address', ReturnGoodViewSet, 'maddress')
routers.register(r'managements/role', RoleListViewSet, 'role')
routers.register(r'managements/reason', ReturnReasonViewSet, 'reason')
routers.register(r'managements/brand', GoodBrandViewSet, 'brand')
routers.register(r'managements/ad', IndexCarouselGoodViewSet, 'ad')
# 基础路由
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include(routers.urls)),
    # path('return/$', PayViewSet.as_view()),
    # url(r'^index/', index),

    url(r'^queryUser/$', QueryUser.as_view()),
    url(r'^productCategory/update', update_cate),
    url(r'^productCategory/navStatus', update_nav),
    url(r'^productCategory/showStatus', update_status),
    url(r'^global/login', global_login),
    url(r'^global/info', global_info),
    url(r'^memberLevel/list', member),
    url(r'^upload_img', test_upload_file),
    url(r'^global/logout', global_logout),
    url(r'^subject/listAll', listAll),
    url(r'product/create', create),
    url(r'role/listAll', role),
    url(r'role/list', role_list),
    url(r'^returnReason/list', returnReason),
    url(r'^productCategory/list/withChildren', withChildren),
    url(r'^productAttribute/category/list', productAttribute),
    url(r'^api-auth/', include('rest_framework.urls')),
    re_path(r'media/(?P<path>.*)$', serve, {'document_root': MEDIA_ROOT}),
    re_path(r'media/(?P<path>.*)$', serve, {'document_root': STATIC_ROOT}),
    # url(r'^api-token-auth/', views.obtain_auth_token),
    # jwt 前后台登录
    # url(r'^login/$', obtain_jwt_token),
    # 需要修改
    url(r'^login/$', CustomObtainJSONWebToken.as_view()),
    # url(r'^logout/$', obtain_jwt_token),
    # 后台登录
    url(r'^admin_login/$', CustomObtainJSONWebToken.as_view()),
    # 文档
    url(r'docs/', include_docs_urls(title='嘉美伯爵')),
    # path('docs/', include_docs_urls(title='嘉美伯爵'))
    # path('swagger-ui/', TemplateView.as_view(
    #     template_name='swagger-ui.html',
    #     extra_context={'schema_url': 'openapi-schema'}
    # ), name='swagger-ui'),
    #
    path('openapi', get_schema_view(
        title="Your Project",
        description="API for all things …",
        version="1.0.0"
    ), name='openapi-schema'),
    url(r'^alipay/return/', AliPayViewSet.as_view(), name="alipay"),
    # url(r'weibo/', WeiboLogin.as_view(), name='weibologin'),
    path('sentry-debug/', trigger_error),
]
